#ifndef _CCAIROTHEME_H_
#define _CCAIROTHEME_H_

#include <buola/widgets/ctheme.h>

namespace buola { namespace gui {

class CCairoTheme : public CTheme
{
public:
    CCairoTheme();
    ~CCairoTheme();

    enum EDecoButton
    {
        DECO_BUTTON_MIN,
        DECO_BUTTON_MAX,
        DECO_BUTTON_CLOSE,
        DECO_BUTTON_DOCK,
        DECO_BUTTONCOUNT
    };

    enum EDecoState
    {
        DECO_STATE_NORMAL,
        DECO_STATE_HOVER,
        DECO_STATE_PRESSED,
        DECO_STATE_INACTIVE,
        DECO_STATECOUNT
    };

private:
    img::CPicture GetImage(const std::string &pName);
    img::CPicture CreateDecoButton(float pHue,const img::CPicture &pBase);

    void InitDeco();
    void Init();

public:
    //controls and their helpers
    CPoint_d GetButtonTextPos(CButton*,const CRect_d&);
    virtual void PrepareButton(CButton*);
    virtual void DrawButton(img::CGC*,CButton*,EDrawStyle);
    virtual void DrawCheckBox(img::CGC*,CCheckBox*,EDrawStyle);
    virtual void DrawComboBox(img::CGC*,CComboBox*,EDrawStyle);
    virtual void PrepareEditBox(CEditBox *pE);
    virtual void DrawEditBox(img::CGC*,CEditBox*,EDrawStyle);
    virtual void DrawLabelBox(img::CGC*,CLabelBox*,EDrawStyle);
    virtual void DrawListBox(img::CGC*,CListBox*,EDrawStyle);
    virtual void PrepareMenuBar(CMenuBar*);
    virtual void DrawMenuBar(img::CGC*,CMenuBar*,EDrawStyle);
    virtual void DrawNumBox(img::CGC*,CNumBox*,EDrawStyle);
    virtual void DrawOptionBox(img::CGC*,COptionBox*,EDrawStyle);
    virtual void DrawProgressBar(img::CGC*,CProgressBar*,EDrawStyle);
    virtual void PrepareRulerBox(CRulerBox*);
    virtual void DrawRulerBox(img::CGC*,CRulerBox*,EDrawStyle);
    virtual void PrepareScrollBar(CScrollBar *pS);
    virtual void DrawScrollBar(img::CGC*,CScrollBar*,EDrawStyle);
    virtual void PrepareSliderBox(CSliderBox *pS);
    virtual void DrawSliderBox(img::CGC*,CSliderBox*,EDrawStyle);
    virtual void DrawStatusBar(img::CGC*,CStatusBar*,EDrawStyle);
    virtual void PrepareTabBox(CTabBox*);
    virtual void DrawTabBox(img::CGC*,const CRect_d&,CTabBox*,EDrawStyle);
    virtual void PrepareToolBar(CToolBar*);
    virtual void DrawToolBar(img::CGC*,CToolBar*,EDrawStyle);
    virtual void DrawTreeBox(img::CGC*,CTreeBox*,EDrawStyle);

    //primitives and their helpers
    virtual void DrawScrollBarCursor(img::CGC *pGC,const CRect_d &pRect,bool pVertical,bool pActive);
    virtual void DrawCheckBoxBox(img::CGC *pGC,const CRect_d &pRect,bool);
    virtual void DrawCursor(img::CGC *pGC,const CRect_d &pRect);
    virtual void DrawHandle(img::CGC *pGC,const CRect_d &pRect,bool=false);
    virtual void PrepareHandleBar(CWindow *pW);
    virtual void DrawHandleBar(img::CGC *pGC,const CRect_d &pR,const std::wstring &pText,EDecoFlags pFlags,EDecoFlags pActive);
    virtual void DrawRulerField(img::CGC*,const CRect_d&,const std::wstring&,bool,bool);
    virtual void DrawRulerFieldHL(img::CGC*,const CRect_d&,const std::wstring&,const img::CColor&,bool);
    virtual void DrawLabel(img::CGC *pGC,const CPoint_d&,const std::wstring&);
    virtual void DrawThinBar(img::CGC*,const CRect_d&);
    virtual void DrawShadow(img::CGC*,const CRect_d&);
    virtual void DrawSplitItem(img::CGC*,const CRect_d&,int pType);
    virtual void DrawSeparationLine(img::CGC*,const CPoint_d&,const CPoint_d&);
    virtual void DrawToolBarItem(img::CGC*,const CRect_d&,CToolBar*,PMenuItem,EDrawStyle);
    virtual void DrawTabBoxItem(img::CGC*,const CRect_d&,CTabBox*,CTabBoxItem*,EDrawStyle);
    virtual void DrawMenuBarItem(img::CGC*,const CRect_d&,CMenuBar*,PMenuItem,EDrawStyle);
    virtual void DrawArrow(img::CGC *pGC,const CPoint_d &pC,EArrow pArrow);

    void DrawDecoButton(img::CGC *pGC,const img::CPicture &pImage,const CRect_d &pD);

    virtual void PrepareDecoration(CWindow *pW);
    virtual void DrawDecoration(img::CGC *pGC,const CRect_d &pR,const std::wstring &pTitle,EDecoFlags pFlags);

    //size hints
    virtual CSize_d GetLabelSize(const std::wstring &pLabel);
    virtual CSize_d GetScrollBarButtonSize();
    virtual int GetSliderSize();
    virtual CSize_d GetMicroButtonSize();
    virtual double GetResizeBarWidth(EDrawStyle);
    virtual double GetAttachHandleWidth(EAttachFlags);

    //helpers
    virtual void SetBackground(CWindow *pWindow,int pType);

private:
    bool mInit,mDecoInit;

    struct
    {
        img::CColor mBase;
        img::CColor mInactive;
        img::CColor mText;
        img::CColor mClose;
        img::CColor mSelected;
    } mColors;

    struct
    {
        img::CPicture mTL,mT,mTR,mL,mR,mBL,mB,mBR;
        img::CPicture mBaseButton[DECO_STATECOUNT];
        img::CPicture mButtons[DECO_BUTTONCOUNT][DECO_STATECOUNT];
    } mDeco;

    img::CPicture mDecoButtonGreen;
    img::CPicture mDecoButtonYellow;
    img::CPicture mDecoButtonBlue;
    img::CPicture mDecoButtonRed;
    img::CPicture mDecoButtonGrey;
    img::CPicture mListBackground;
    CColorMatrixPool mRoundButton;
    CColorMatrixPool mRectButton;
    CColorMatrixPool mRotRectButton;
    CColorMatrixPool mCombo;
    CColorMatrixPool mRotCombo;
    CColorMatrixPool mTab;
    CColorMatrixPool mTabInvert;
    CColorImagePool mTabBase;
    CColorImagePool mBack;
    CColorImagePool mCheckBoxOn,mCheckBoxOff;
    CColorImagePool mOptionBoxOn,mOptionBoxOff;
    CColorImagePool mHSliderArrow;
    CColorImagePool mVSliderArrow;

    CColorMatrixPool mVBack,mVSlider,mVISlider;
    CColorImagePool mVButton;
    CColorMatrixPool mHBack,mHSlider,mHISlider;
    CColorImagePool mHButton;
    img::PFont mFont;
    img::PFont mBoldFont;
    img::PFont mMenuFont;
    img::PFont mMenuBoldFont;
    img::PFont mFont90;
    img::PFont mSmallFont;
    CColorImagePool mMicroButton,mMicroButtonHover,mMicroButtonDown;
    img::CPicture mCloseIcon;
    img::CColor mMicroColor,mCloseColor;

//    CSize_d mShadowSize;
//    img::CSurface *mShadow;
//    img::CSurface *mBlackPicture;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
